/*
 * @Date: 2021-08-17 17:44:53
 * @information:
 */
import {
  request,
  summary,
  description, // 接口名称下方的描述信息
  query, // get时参数
  path, // post, put, delete 时地址栏参数
  body, // body中的参数
  tags
} from 'koa-swagger-decorator'

import UserService from '../service/UserService'


const userService = new UserService()
const tag = tags(['User'])

export default class UserController {
  @request('post', '/user/findById')
  @summary('根据id查询用户数据')
  @tag
  @body({
    id: { type: 'string', required: true },
  })
  async findById (ctx) {
    const bObj = ctx.request.body
    const data = await userService.findById(bObj)
    ctx.rest(data)
  }

  @request('post', '/user/add')
  @summary('添加一条用户数据')
  @tag
  @body({
    username: { type: 'string', required: true },
    sex: { type: 'string', required: false },
    avatarUrl: { type: 'string', required: false },
    phone: { type: 'string', required: false },
    desc: { type: 'string', required: false },
  })
  async add (ctx) {
    let bObj = ctx.request.body
    const res = await userService.add(bObj)
    ctx.rest(res.id)
  }



}

